//
//  GameViewObject.m
//  2048
//
//  Created by 高新川 on 15/6/7.
//  Copyright (c) 2015年 高新川. All rights reserved.
//

#import "GameViewObject.h"
#import "Game.h"
#import "PaneView.h"

@implementation GameViewObject

- (id)init {
    self = [super init];
    if (self) {
        _viewArray = [[NSMutableArray alloc] initWithCapacity:6];
        for (int index = 0; index < 6; index++) {
            NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:6];
            for (int j = 0; j < 6; j++) {
                PaneView *view = [[PaneView alloc] init];
                view.layer.cornerRadius = 8.0;
                view.backgroundColor = [UIColor colorWithHexString:@"CCCCCC"];
                [array addObject:view];
            }
            [_viewArray addObject:array];
        }
        
        _dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"CCCCCC",@"0",
                       @"#C6E2FF",@"2",
                       @"#C1FFC1",@"4",
                       @"#CD950C",@"8",
                       @"#D15FEE",@"16",
                       @"#EE7621",@"32",
                       @"#EE82EE",@"64",
                       @"#EE6A50",@"128",
                       @"#DC143C",@"256",
                       @"#7FFF00",@"512",
                       @"#32CD32",@"1024",
                       @"#FFFF00",@"2048",
                       @"#FFB90F",@"4096",
                       @"#FF7F50",@"9192",nil];
    }
    return self;
}

- (void)initViews {
    
}

- (void)showNumbers {
    DataModel *model = [Game getInstance].model;
    for (int i = 0; i<_size; i++) {
        for (int j = 0; j<_size; j++) {
            NSString *text = [model objectAtToString:i and:j];
            NSString *color = [_dictionary objectForKey:text];
            PaneView *view = [[self.viewArray objectAtIndex:i] objectAtIndex:j];
            view.backgroundColor = [UIColor colorWithHexString:color];
            if (false == [text isEqualToString:@"0"]) {
                view.textLabel.text = text;
            }
            else {
                view.textLabel.text = @"";
            }
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
